package com.alks.function.controller;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.entity.*;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.prod.ProdDynamicDetailRequest;
import com.alks.function.data.request.prod.ProdDynamicRequest;
import com.alks.function.service.PcProdDynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author:xxxxx
 * @create: 2023-07-04 10:34
 * @Description: 生产动态
 */
@Api(tags = {"荣阳查询 -- 生产动态", "开发-总进度", "开发-计划安排", "开发-部门月目标设定", "开发-研发部门日计划"})
@ApiRestController("/prod")
public class PcProdDynamicController {
    @Autowired
    PcProdDynamicService pcProdDynamicService;

    @GetMapping("/getPcProdDynamicCondition")
    @ApiOperation(value = "生产动态查询条件", tags = "荣阳查询 -- 生产动态")
    @WebLogger
    public ResponseInfo getPcProdDynamicCondition() {
        return pcProdDynamicService.listPcDynamicCondition();
    }

    @PostMapping("/getPcProdDynamicList")
    @ApiOperation(value = "生产动态查询", tags = "荣阳查询 -- 生产动态")
    @WebLogger
    public ResponseInfo getPcProdDynamicList(@RequestBody ProdDynamicRequest request) {
        return pcProdDynamicService.getPcProdDynamicList(request);
    }

    @WebLogger
    @PostMapping("/getProdDynamicDetail")
    @ApiOperation(value = "材料明细查询", tags = "荣阳查询 -- 生产动态")
    public ResponseInfo getProdDynamicDetail(@RequestBody ProdDynamicDetailRequest request) {
        return pcProdDynamicService.getProdDynamicDetail(request);
    }

    //开发-总进度 进度安排 待排订单安排查询
    @WebLogger
    @PostMapping("/prod/getPreOrderList")
    @ApiOperation(value = "待排订单资料", tags = "开发-总进度")
    public ResponseInfo getPreOrderList(@RequestBody PcProdPreReq req) {
        return pcProdDynamicService.getPreOrderList(req);
    }

    //基础资料建档
    @GetMapping("/prod/getLine1")
    @ApiOperation(value = "基础资料建档", tags = "开发-总进度")
    @WebLogger
    public ResponseInfo  getLine1() {
        return pcProdDynamicService.getLine1();
    }

    //修改生产组别日产量
    @PostMapping("/prod/updatePcLine1")
    @ApiOperation(value = "修改", tags = "开发-总进度")
    @WebLogger
    public ResponseInfo updatePcLine1(@RequestBody Map<String,Object> map){
        return pcProdDynamicService.updatePcLine1(map);
    }

    //判断该表中是否存在该指令的数据 存在的话就不能进行指令恢复的操作 不存在则可以进行指令恢复的操作
    //指令恢复

    @PostMapping("/prod/downloadPcOrderSch")
    @ApiOperation(value = "导出进度表", tags = "开发-总进度")
    @WebLogger
    public void downloadPcOrderSch(HttpServletResponse response) throws IOException {
        pcProdDynamicService.downloadPcOrderSch(response);
    }

    @WebLogger
    @PostMapping("/prod/updateRecoverLot")
    @ApiOperation(value = "指令结束、指令恢复、安排进度、取消安排", tags = "开发-总进度")
    public ResponseInfo updateRecoverLot(@RequestBody PcLotRecoverReq req) {
        return pcProdDynamicService.updateRecoverLot(req);
    }
    //指令结束

    @WebLogger
    @GetMapping("/prod/getPcScheduleList")
    @ApiOperation(value = "进度安排资料查询", tags = "开发-总进度")
    public ResponseInfo getPcScheduleList(@RequestParam(required = false) String lotNo, @RequestParam(required = false) String shoeName, @RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        return pcProdDynamicService.getPcScheduleList(lotNo, shoeName, pageNum, pageSize);
    }

    //取进度表资料
    @WebLogger
    @PostMapping("/prod/updateScheduleDetail")
    @ApiOperation(value = "取进度表资料", tags = "开发-总进度")
    public ResponseInfo updateScheduleDetail() {
        return pcProdDynamicService.updateScheduleDetail();
    }

    //计算进度排序规则
    @WebLogger
    @PostMapping("/prod/computeProdDate")
    @ApiOperation(value = "计算进度", tags = "开发-总进度")
    public ResponseInfo computeProdDate(@RequestParam @ApiParam(required = true, name = "order", value = "1: 按交期排序 2：按调整排序") String order) {
        return pcProdDynamicService.computeProdDate(order);
    }

    @PostMapping("/prod/updatePcScheduleLot")
    @ApiOperation(value = "更新指令", tags = "开发-总进度")
    @WebLogger
    public ResponseInfo updatePcScheduleLot(){
        return pcProdDynamicService.updatePcScheduleLot();
    }

    @WebLogger
    @PostMapping("/prod/upDown")
    @ApiOperation(value = "上移、下移", tags = "开发-总进度")
    public ResponseInfo upDown(@RequestParam @ApiParam(required = true, name = "upDown", value = "1: 上移 2：下移") String upDown,
                               @RequestBody List<PcScheduleRep1> req) {
        return pcProdDynamicService.upDown(upDown, req);
    }

    @WebLogger
    @PostMapping("/prod/batchMove")
    @ApiOperation(value = "批量改序号", tags = "开发-总进度")
    public ResponseInfo batchMove(@RequestBody BatchMoveReq req) {
        return pcProdDynamicService.batchMove(req);
    }

    //计划安排
    @WebLogger
    @PostMapping("/plan/arrangePlanList")
    @ApiOperation(value = "计划安排查询", tags = "开发-计划安排")
    public ResponseInfo arrangePlanList(@RequestBody PcProdArrangeReq req) {
        return pcProdDynamicService.arrangePlanList(req);
    }

    @WebLogger
    @PostMapping("/plan/downloadExcelPlan")
    @ApiOperation(value = "计划安排查询导出", tags = "开发-计划安排")
    public void downloadExcelPlan(HttpServletResponse response, @RequestBody PcProdArrangeReq req) throws IOException {
        pcProdDynamicService.downloadExcelPlan(req, response);
    }

    //选择指令查询
    @WebLogger
    @PostMapping("/plan/choosePlanList")
    @ApiOperation(value = "选择指令查询", tags = "开发-计划安排")
    public ResponseInfo choosePlanList(@RequestBody PcProdArrangeReq req) {
        return pcProdDynamicService.choosePlanList(req);
    }

    //选择指令选择
    @WebLogger
    @PostMapping("/plan/chooseProdStatusIn")
    @ApiOperation(value = "选择", tags = "开发-计划安排")
    public ResponseInfo chooseProdStatusIn(@RequestBody List<String> list, @RequestParam @ApiParam(required = true,
            value = "1:物料 2：板房 3：针车 4：大底 5：成型") String choose) {
        return pcProdDynamicService.chooseProdStatusIn(list, choose);
    }

    //更新指令 移除指令
    @WebLogger
    @PostMapping("/plan/updatePcOrderPlan")
    @ApiOperation(value = "更新计划", tags = "开发-计划安排")
    public ResponseInfo updatePcOrderPlan(@RequestBody MtlDPlanArrangeRep req, @RequestParam @ApiParam(required = true,
            value = "1:物料 2：板房 3：针车 4：大底 5：成型") String choose) {
        return pcProdDynamicService.updatePcOrderPlan(req, choose);
    }

    @WebLogger
    @PostMapping("/plan/removePcOrderPlan")
    @ApiOperation(value = "删除", tags = "开发-计划安排")
    public ResponseInfo removePcOrderPlan(@RequestBody MtlDPlanArrangeRep req, @RequestParam @ApiParam(required = true,
            value = "1:物料 2：板房 3：针车 4：大底 5：成型") String choose) {
        return pcProdDynamicService.removePcOrderPlan(req, choose);
    }

    @WebLogger
    @PostMapping("/develop/prodStatusList")
    @ApiOperation(value = "查询、去上月设定资料", tags = "开发-部门月目标设定")
    public ResponseInfo cutProdStatusList(@RequestParam @ApiParam(required = false, value = "传入时间格式转换为 yyyyMM") String date,
                                          @RequestParam @ApiParam(required = false, value = "1:查询,2:取上月设定资料") String choose,
                                          @RequestParam Integer pageNum,
                                          @RequestParam Integer pageSize) {
        return pcProdDynamicService.cutProdStatusList(date, choose, pageNum, pageSize);
    }

    //更新
    @WebLogger
    @PostMapping("/develop/updateProdStatus")
    @ApiOperation(value = "添加、删除、插入数据", tags = "开发-部门月目标设定")
    public ResponseInfo updateProdStatus(@RequestBody PcCutProdStatusRep req,
                                         @RequestParam @ApiParam(required = true, value = "1:插入 2：删除 3：更新 序号月份不能修改") String choose) {
        return pcProdDynamicService.updateProdStatus(req, choose);
    }

    //研发部门日计划
    @WebLogger
    @PostMapping("/develop/devPartDayPlanList")
    @ApiOperation(value = "计划明细", tags = "开发-研发部门日计划")
    public ResponseInfo devPartDayPlanList(@RequestBody PcDevPartDayPlanReq req) {
        return pcProdDynamicService.devPartDayPlanList(req);
    }

    @WebLogger
    @PostMapping("/develop/downloadDayPlanList")
    @ApiOperation(value = "计划明细导出", tags = "开发-研发部门日计划")
    public void downloadDayPlanList(HttpServletResponse response, @RequestBody PcDevPartDayPlanReq req) throws IOException {
        pcProdDynamicService.downloadDayPlanList(response,req);
    }

    @WebLogger
    @PostMapping("/develop/radPartDayPlan")
    @ApiOperation(value = "修改、删除", tags = "开发-研发部门日计划")
    public ResponseInfo radPartDayPlan(@RequestBody MtlDPlanArrangeRep req, @RequestParam @ApiParam(required = true, value = "1: 更新、2：移除指令") String choose) {
        return pcProdDynamicService.radPartDayPlan(req, choose);
    }


    //开发样品周计划导入
    @PostMapping("/uploadPcOrderShoePlan")
    @WebLogger
    @ApiOperation(value = "开发样品周计划导入",tags = "开发-研发部门日计划")
    public ResponseInfo uploadPcOrderShoePlan(MultipartFile file) throws IOException {
        return pcProdDynamicService.uploadPcOrderShoePlan(file);
    }

    //节点
    @WebLogger
    @GetMapping("/develop/getLine")
    @ApiOperation(value = "节点", tags = "开发-研发部门日计划")
    public ResponseInfo getLine() {
        return pcProdDynamicService.getLine();
    }
}
